Week3:hw3 判斷質數


Posted by rockyooooooo on 2021-04-19

這一題要先找出數字的所有因數,所以直接用上一周 hw4:印出因數的 code 來改寫
因為質數只會有兩個因數, 1 跟自己
唯一的例外數字 1,既不是合數也不是因數,按題目要求,視為合數處理

  1. 先把所有因數都存在一個 array
  2. array 的長度就是因數的個數









Related Posts

leetcode-Remove Duplicates from an Array (ES6)

leetcode-Remove Duplicates from an Array (ES6)

CS50 Hash Table

CS50 Hash Table

CH8-2 while迴圈

CH8-2 while迴圈


Comments